var revenue = [1000, 5000, 10000, 9999999];
var reward = [0.9, 0.95, 0.99, 1];

function result() {
	var baojia = document.getElementById("txtBaojia");
	var chengben = document.getElementById("seChengben");
	var yuedu = document.getElementById("txtYuedu");
	var yueduzhanbi = document.getElementById("lbYuedupercent");
	yueduzhanbi.value = reward[find(revenue, yuedu.value)] * 100 + "%";
	if (yuedu.value == "" || baojia.value == "") {
		yueduzhanbi.value = "";
		return;
	}
	var jieguo = document.getElementById("lbResult");
	
	var numJieguo = baojia.value / chengben.value / yuedu.value * reward[find(revenue, yuedu.value)];
	jieguo.innerText = Math.round(numJieguo * 10000) / 10000;
}

function find(array, val) {
	//如果值小于revenue最小的值时，则奖励0
	if (val < Math.min.apply(null, array)) {
		return 0;
	}
	//如果值大于revenue最大的值时，则奖励最高一档
	if (val > Math.max.apply(null, array)) {
		return array.length - 1;
	}
	var idx = 0,
		i = 0,
		j = array.length;
	for (i; i < j; i++) {
		if (array[i] > val) {
			idx = i;
			break;
		};
	};
	return idx;
};
